package org.artifact.xlsx;

import cn.hutool.core.io.FileUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ConvertUtil {
    static final Log log = LogFactory.get();
    // 输入路径
    static String inputPath = "C:\\Users\\Administrator\\Desktop\\gameConfig";
    // 输出路径
    static String outputPath = "C:\\Users\\Administrator\\Desktop\\gameConfig";
    // 转换器
    static List<AbstractConvert> converts = new ArrayList<>();
    // 语言文字
    static Map<String,String> i18n = new HashMap<>();

    public static void main(String[] args) {
        log.info("输入路径：{}", inputPath);
        log.info("输出路径：{}", outputPath);


        converts.add(new ClientConvert());
        converts.add(new ServerConvert());

        List<File> files = FileUtil.loopFiles(inputPath, new FileFilter() {
            @Override
            public boolean accept(File file) {
                if (FileUtil.pathEndsWith(file, "xlsx")) {
                    return true;
                } else if (FileUtil.pathEndsWith(file, "xls")) {
                    return true;
                } else if (FileUtil.pathEndsWith(file, "xlsm")) {
                    return true;
                } else if (FileUtil.pathEndsWith(file, "yml")) {
                    return true;
                } else {
                    return false;
                }
            }
        });

        for (File file : files) {
            String type = FileUtil.getType(file);
            for (AbstractConvert convert : converts) {
                switch (type){
                    case "yml":
                        convert.convertYml(file,outputPath);
                        break;
                    case "xls":
                    case "xlsx":
                    case "xlsm":
                        convert.convertXlsx(file,outputPath);
                        break;
                }
            }
        }
        for (AbstractConvert convert : converts) {
            convert.writeI18nFile(outputPath);
        }
    }
}
